﻿namespace PasswordGeneratorTests
{
    using System.Linq;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using PasswordGenerator;

    /// <summary>
    /// This is a test class for PasswordGeneratorTest and is intended
    /// to contain all PasswordGeneratorTest Unit Tests
    ///</summary>
    [TestClass()]
    public class PasswordGeneratorRngTest
    {

        [TestMethod()]
        public void PasswordGenerator_Rng_GenerateAllCategoriesTest()
        {
            var target = new PasswordGenerator(new RngCryptoProvider());
            target.UseCapitalCharacters = true;
            target.UseNumbers = true;
            target.UseSmallCharacters = true;
            target.UseSpecialCharacters = true;
            target.PasswordLength = 10000;

            string s = target.Generate();

            Assert.IsNotNull(s);
            Assert.AreEqual(target.Password, s);
        }

        [TestMethod()]
        public void PasswordGenerator_Rng_GenerateCapitalCharsTest()
        {
            var target = new PasswordGenerator(new RngCryptoProvider());
            target.UseCapitalCharacters = true;
            target.UseNumbers = false;
            target.UseSmallCharacters = false;
            target.UseSpecialCharacters = false;
            target.PasswordLength = 10000;

            string s = target.Generate();

            Assert.IsNotNull(s);
            Assert.AreEqual(target.Password, s);
            Assert.IsTrue(s.All(x => char.IsUpper(x)));
        }

        [TestMethod()]
        public void PasswordGenerator_Rng_GenerateSmallCharsTest()
        {
            var target = new PasswordGenerator(new RngCryptoProvider());
            target.UseCapitalCharacters = false;
            target.UseNumbers = false;
            target.UseSmallCharacters = true;
            target.UseSpecialCharacters = false;
            target.PasswordLength = 10000;

            string s = target.Generate();

            Assert.IsNotNull(s);
            Assert.AreEqual(target.Password, s);
            Assert.IsTrue(s.All(x => char.IsLower(x)));
        }

        [TestMethod()]
        public void PasswordGenerator_Rng_GenerateNumbersTest()
        {
            var target = new PasswordGenerator(new RngCryptoProvider());
            target.UseCapitalCharacters = false;
            target.UseNumbers = true;
            target.UseSmallCharacters = false;
            target.UseSpecialCharacters = false;
            target.PasswordLength = 10000;

            string s = target.Generate();

            Assert.IsNotNull(s);
            Assert.AreEqual(target.Password, s);
            Assert.IsTrue(s.All(x => char.IsDigit(x)));
        }

        [TestMethod()]
        public void PasswordGenerator_Rng_GenerateSpecialCharsTest()
        {
            var target = new PasswordGenerator(new RngCryptoProvider());
            target.UseCapitalCharacters = false;
            target.UseNumbers = false;
            target.UseSmallCharacters = false;
            target.UseSpecialCharacters = true;
            target.PasswordLength = 10000;

            string s = target.Generate();

            Assert.IsNotNull(s);
            Assert.AreEqual(target.Password, s);
            Assert.IsTrue(s.All(x => !char.IsDigit(x) && !char.IsLower(x) || !char.IsUpper(x)));
        }

        [TestMethod()]
        public void PasswordGenerator_Rng_GenerateBigSmallTest()
        {
            var target = new PasswordGenerator(new RngCryptoProvider());
            target.UseCapitalCharacters = true;
            target.UseNumbers = false;
            target.UseSmallCharacters = true;
            target.UseSpecialCharacters = false;
            target.PasswordLength = 10000;

            string s = target.Generate();

            Assert.IsNotNull(s);
            Assert.AreEqual(target.Password, s);
        }

        [TestMethod()]
        public void PasswordGenerator_Rng_GenerateBigSmallNumberTest()
        {
            var target = new PasswordGenerator(new RngCryptoProvider());
            target.UseCapitalCharacters = true;
            target.UseNumbers = true;
            target.UseSmallCharacters = true;
            target.UseSpecialCharacters = false;
            target.PasswordLength = 10000;

            string s = target.Generate();

            Assert.IsNotNull(s);
            Assert.AreEqual(target.Password, s);
        }

        [TestMethod()]
        public void PasswordGenerator_Rng_GenerateLongPassword()
        {
            var target = new PasswordGenerator(new RngCryptoProvider());
            target.UseCapitalCharacters = true;
            target.UseNumbers = true;
            target.UseSmallCharacters = true;
            target.UseSpecialCharacters = false;
            target.PasswordLength = 100000;

            string s = target.Generate();

            Assert.IsNotNull(s);
            Assert.AreEqual(target.Password, s);
        }
    }
}
